package com.boyuan.config.entity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@JsonSerialize(include= JsonSerialize.Inclusion.NON_NULL)
public class ResponseData<T>  implements Serializable {
    private String message;
    private int status;
    private Map<String,T> data = new HashMap<>();

    public String getMessage() {
        return message;
    }

    public int getStatus() {
        return status;
    }

    public Map<String, T> getData() {
        return data;
    }

    public ResponseData putDataValue(String key, T value) {
        data.put(key,value);
        return this;
    }

    public ResponseData(int status , String message) {
        this.message = message;
        this.status = status;
    }

    public static<T> ResponseData<T> sussess(){
        return new ResponseData(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDesc());
    }
    public static<T> ResponseData<T> requestBad(){
        return new ResponseData(ResponseCode.REQUESTBAD.getCode(),ResponseCode.REQUESTBAD.getDesc());
    }
    public static<T> ResponseData<T> forbidden(){
        return new ResponseData(ResponseCode.FORBIDDEN.getCode(),ResponseCode.FORBIDDEN.getDesc());
    }
    public static<T> ResponseData<T> notFound(){
        return new ResponseData(ResponseCode.NOTFOUND.getCode(),ResponseCode.NOTFOUND.getDesc());
    }
    public static<T> ResponseData<T> serverError(){
        return new ResponseData(ResponseCode.SERVERERROR.getCode(),ResponseCode.SERVERERROR.getDesc());
    }public static<T> ResponseData<T> unauthorized(){
        return new ResponseData(ResponseCode.UNAUTHORIZED.getCode(),ResponseCode.UNAUTHORIZED.getDesc());
    }public static<T> ResponseData<T> customError(){
        return new ResponseData(ResponseCode.CUSTOMERROR.getCode(),ResponseCode.CUSTOMERROR.getDesc());
    }
}
